package com.tianqicode.demo.proxy;

import com.tianqicode.demo.dao.ServiceDao;
import com.tianqicode.demo.service.IService;
import com.tianqicode.spring.beans.factory.FactoryBean;

import java.lang.reflect.Proxy;

public class ServiceProxy implements FactoryBean<ServiceDao> {

    @Override
    public ServiceDao getObject() throws Exception {
        ServiceDao serviceDao = (ServiceDao) Proxy.newProxyInstance(
                Thread.currentThread().getContextClassLoader(), new Class[]{ServiceDao.class}, ((proxy, method, args1) -> method));
        return serviceDao;
    }

    @Override
    public Class<?> getObjectType() {
        return IService.class;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }
}
